﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AdvCMS.Data.Repositories;
using AdvCMS.Data.Linq.Repositories;

namespace AdvCMS.Factory
{
    public class RepositoryFactory
    {
        public AdvCMS.Data.Linq.PagesDataContext PageContext;
        public AdvCMS.Data.Linq.UsersDataContext userContext;
        public IPageRepository NewPageRepository()
        {
            PageRepository repository = new PageRepository();
            repository.DataContext = GetPageContext();
            return repository;
        }

        public IUserRepository NewUserRepository()
        {
            UserRepository repository = new UserRepository();
            repository.DataContext = GetUserContext();
            return repository;
 
        }

        private AdvCMS.Data.Linq.PagesDataContext GetPageContext()
        {
            if (PageContext == null)
            {
                PageContext = new Data.Linq.PagesDataContext();
            }

            return PageContext;
        }

        private AdvCMS.Data.Linq.UsersDataContext GetUserContext()
        {
            if(userContext == null)
            {
                userContext = new Data.Linq.UsersDataContext();
            }
            return userContext;
        }
    }
}
